﻿(function (e) {
    function g(a) { for (var c = 0; c < b.length; c++) if (b[c].o == a) { b[c].animating || (animating = !0, e(a).animate({ left: b[c].direction + d.amount + "px" }, d.speed, d.easing, function () { b[c].direction = "-=" == b[c].direction ? "+=" : "-="; b[c].animating = !1; b[c].interval++; b[c].interval >= d.number && e(a).animate({ left: b[c].position + "px" }, d.speed, d.easing, function () { b[c].execute = !1 }) })); break } } var d = _defaults = null, b = [], f = { init: function (a) {
        d = _defaults = e.extend({ easing: "linear", number: 7, speed: 2, amount: 4, selector: this.selector },
a); 0 >= d.number && (d.number = 1); e(this.selector).css("position", "relative"); b.push({ o: this.selector, position: e(this.selector).css("left") }); f.reset(this.selector)
    }, reset: function (a) { for (var c = 0; c < b.length; c++) if (b[c].o == a) { b[c].direction = "-="; b[c].animating = !1; b[c].execute = !1; b[c].interval = 0; break } }, start: function () { f.reset(this.selector); for (var a = 0; a < b.length; a++) if (b[a].o == this.selector) { b[a].execute = !0; break } }, stop: function () {
        f.reset(this.selector); for (var a = 0; a < b.length; a++) if (b[a].o == this.selector) {
            e(this.selector).animate({ marginLeft: b[a].position +
"px"
            }, d.speed, d.easing); break
        } 
    } 
    }; setInterval(function () { e.grep(b, function (a) { a.execute && g(a.o) }) }, 50); e.fn.alertShake = function (a) { if (f[a]) return f[a].apply(this, Array.prototype.slice.call(arguments, 1)); if ("object" === typeof a || !a) return f.init.apply(this, arguments); e.error("Method " + a + " does not exist on jQuery.alertShake."); return !1 } 
})(jQuery, window, document);

function onSignMouseOver() {
    document.body.style.cursor = 'pointer';
}

function onSignMouseOut() {
    document.body.style.cursor = 'default';
}

function signupBack() {
    $("#divSignUp").slideUp();
    $("#divDestination").slideDown();
}

var idx = 0;

function start() {

        var island = [
		'<article>',
 		'<div class="circle">',
        	'<div class="entence" id="entence">',
			'<div class="logo"></div>',
        		'<div id="divDestination" class="mainCenter">',
        			'<div class="mainCenterMiddle">',
        				'<div class="row">',
        					'<div class="ui-widget">',
        						'<label for="txtDestination" class="destinationsearch">Discover a whole new travel experience<span>Get an early preview</span></label> ',
        						'<input type="text" id="txtDestination" name="txtDestination" class="destinationdrop" tabindex="1" value="Your dream destination" onclick="this.value = \'\';" />',           
        					'</div>',
        				'</div>',
        				'<div class="row">',
        					'<input type="button" id="btndestinationNext" value="go" class="destinationgo" tabindex="2" onmouseover="onSignMouseOver()" onmouseout="onSignMouseOut()"/>',
        				'</div>',
        			'</div>',
        		'</div>',
        		'<div id="divSignUp" class="mainCenter" style="display:none;">',
        			'<div class="mainCenterMiddle">',
        				'<div class="row">',
        					'<label for="txtDestination" class="requesttext">Request your invite<span>and we\'ll notify you when we\'re boarding</span></label>', 
        					'<label for="txtFirstName"></label>',
        					'<input type="text" id="txtName" name="txtName" class="sillkname" value="Your Name" onclick="this.value = \'\';" tabindex="3"/>',
        				'</div>',
        				'<div class="row">',
        					'<label for="txtEmail2"></label>',
        					'<input type="text" id="txtEmail" name="txtEmail" class="sillkemail" value="Your Email Address" onclick="this.value = \'\';" tabindex="5"/>',
        				'</div>',
        				'<div class="row">',
        					'<input type="button" id="btncreateProfile" value="Request Invite" class="requestinvite" tabindex="6" onmouseover="onSignMouseOver()" onmouseout="onSignMouseOut()"/>',
        				'</div>',    
        			'</div>',
        		'</div>',
        	'</div>',
        '</div>',
		'</article>'
        ].join('');

        if (idx == 0) {
            $('.container').data('plugin_curtain').insert({
                html: island,
                htmlId: 'island',
                htmlClass: 'cover',
                insertAfter: '', // If null, the content is inserted at the end
                goTo: true // Go to the new panel directly after the insertion (default: true)
            });

            idx = 1;
        }

        // setup form of island
        setupForm();
}

function setupForm() {
    $('#txtDestination').alertShake();
    $('#txtName').alertShake();
    $('#txtEmail').alertShake();

    $("#btndestinationNext").click(function () {
        var hasError = false;

        var destinationVal = $("#txtDestination")[0].value;
        if (destinationVal == '' || destinationVal == 'Your dream destination') {
            $('#txtDestination').alertShake('start');
            hasError = true;
        }

        if (hasError == true) {
            return false; // exist out
        }
        else {
            // show next information collection screen
            $("#divDestination").slideUp();
            $("#divSignUp").slideDown();
        }
    });

    $("#btncreateProfile").click(function () {
        $(".signUpError").hide();
        var hasError = false;
        var hasName = false;
        var hasEmail = false;
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

        var nameVal = $("#txtName")[0].value;
        var emailVal = $("#txtEmail")[0].value;

        if (nameVal == '' || nameVal == 'Your Name') {
            $('#txtName').alertShake('start');
            hasError = true;
        }
        else {
            hasName = true;
        }

        if (emailVal == '' || emailVal == 'Your Email Address') {
            $('#txtEmail').alertShake('start');
            hasError = true;
        }
        else if (!emailReg.test(emailVal)) {
            $('#txtEmail').alertShake('start');
            hasError = true;
        }
        else {
            hasEmail = true;
        }

        if (hasError) {
            return false; // exist out
        }
        else {
            // call function from /Scripts/createProfile.js
            createProfile();
        }

    });
}
